package com.atguigu.daijia.customer.service.impl;

import com.atguigu.daijia.coupon.client.CouponFeignClient;
import com.atguigu.daijia.customer.service.CouponService;
import com.atguigu.daijia.model.vo.base.PageVo;
import com.atguigu.daijia.model.vo.coupon.AvailableCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoReceiveCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoUseCouponVo;
import com.atguigu.daijia.model.vo.coupon.UsedCouponVo;
import com.atguigu.daijia.model.vo.order.OrderBillVo;
import com.atguigu.daijia.order.client.OrderInfoFeignClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class CouponServiceImpl implements CouponService {

    private final CouponFeignClient couponFeignClient;
    private final OrderInfoFeignClient orderInfoFeignClient;

    /**
     * 分页查询乘客未领取的优惠券列表
     * @param customerId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageVo<NoReceiveCouponVo> findNoReceiveCouponPage(Long customerId, Long page, Long limit) {
        return couponFeignClient.findNoReceiveCouponPage(customerId, page, limit).getData();
    }

    /**
     * 分页查询乘客未使用的优惠券列表
     * @param customerId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageVo<NoUseCouponVo> findNoUseCouponPage(Long customerId, Long page, Long limit) {
        return couponFeignClient.findNoUseCouponPage(customerId, page, limit).getData();
    }

    /**
     * 分页查询乘客已使用的优惠券列表
     * @param customerId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageVo<UsedCouponVo> findUsedCouponPage(Long customerId, Long page, Long limit) {
        return couponFeignClient.findUsedCouponPage(customerId, page, limit).getData();
    }

    /**
     * 领取优惠券
     * @param customerId
     * @param couponId
     * @return
     */
    @Override
    public Boolean receiveCoupon(Long customerId, Long couponId) {
        return couponFeignClient.receiveCoupon(customerId, couponId).getData();
    }

    /**
     * 查询可用优惠券列表
     * @param customerId
     * @param orderId
     * @return
     */
    @Override
    public List<AvailableCouponVo> findAvailableCouponList(Long customerId, Long orderId) {
        OrderBillVo orderBillVo = orderInfoFeignClient.getOrderBillInfo(orderId).getData();
        return couponFeignClient.findAvailableCouponList(customerId, orderBillVo.getPayAmount()).getData();
    }
}
